using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.EventSystems;

public class RockerIcon : MonoBehaviour,IDragHandler,IEndDragHandler
{
    public Vector3 dir,begionPos;
    public float space;
    public float r = 120;
    public RectTransform rect;
    void Start()
    {
        begionPos = transform.position;
        rect = transform.GetComponent<RectTransform>();
    }
    public float Mover(string name)
    {
        if (name== "Horizontal")
        {
            return rect.anchoredPosition.x * r;
        }
        else if (name== "Vertical")
        {
            return rect.anchoredPosition.y * r;
        }
        else
        {
            return 0;
        }
    }
    public void OnDrag(PointerEventData eventData)
    {
        space = Vector3.Distance(begionPos, Input.mousePosition);
        if (space<=r)
        {
            transform.position = Input.mousePosition;
        }
        else
        {
            dir = Input.mousePosition - begionPos;
            transform.position = begionPos + dir.normalized * r;
        }
    }

    public void OnEndDrag(PointerEventData eventData)
    {
          transform.position = begionPos;
    }
}
